package com.neusoft.yiyang.care.controller;

import com.neusoft.yiyang.common.entity.care.CareLevelItem;
import com.neusoft.yiyang.care.service.CareLevelItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "护理级别-项目关联接口", description = "管理护理级别与护理项目的多对多关联关系")
@RestController
@RequestMapping("/care-level-items")
public class CareLevelItemController {

    @Autowired
    private CareLevelItemService careLevelItemService;

    @Operation(summary = "根据护理级别获取关联项目", description = "查询指定护理级别下配置的所有护理项目")
    @GetMapping("/by-care-level/{careLevelId}")
    public List<CareLevelItem> getCareLevelItemsByCareLevelId(
            @Parameter(description = "护理级别ID", required = true) @PathVariable Integer careLevelId) {
        return careLevelItemService.getCareLevelItemsByCareLevelId(careLevelId);
    }

    @Operation(summary = "根据护理项目获取关联级别", description = "查询指定护理项目被配置到了哪些护理级别中")
    @GetMapping("/by-care-item/{careItemId}")
    public List<CareLevelItem> getCareLevelItemsByCareItemId(
            @Parameter(description = "护理项目ID", required = true) @PathVariable Integer careItemId) {
        return careLevelItemService.getCareLevelItemsByCareItemId(careItemId);
    }

    @Operation(summary = "添加关联关系", description = "建立护理级别与护理项目的关联（配置某个级别需要执行的项目）")
    @PostMapping("/add")
    public void addCareLevelItem(
            @Parameter(description = "护理级别-项目关联信息", required = true) @RequestBody CareLevelItem careLevelItem) {
        careLevelItemService.addCareLevelItem(careLevelItem);
    }

    @Operation(summary = "删除关联关系", description = "解除护理级别与护理项目的关联（从某个级别中移除项目）")
    @DeleteMapping("/delete/{careLevelId}/{careItemId}")
    public void deleteCareLevelItem(
            @Parameter(description = "护理级别ID", required = true) @PathVariable Integer careLevelId,
            @Parameter(description = "护理项目ID", required = true) @PathVariable Integer careItemId) {
        careLevelItemService.deleteCareLevelItem(careLevelId, careItemId);
    }
}